package com.ldf.tool.service.impl;

import com.ldf.tool.service.ITestTaskService;
import org.camunda.bpm.engine.*;
import org.camunda.bpm.engine.repository.ProcessDefinition;
import org.camunda.bpm.engine.runtime.ProcessInstance;
import org.camunda.bpm.engine.task.Task;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author DunFan.Liao
 * @date 2024/3/12 16:49
 */
@Service(ITestTaskService.BEAN_ID)
public class TestTaskServiceImpl implements ITestTaskService {



    @Override
    public void startProcess() {
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        RuntimeService runtimeService = processEngine.getRuntimeService();
        ProcessInstance instance = runtimeService.startProcessInstanceByKey("Process_0ixazrb");
        System.out.println(instance.toString());
    }

    @Override
    public List<ProcessDefinition> findProcesses() {
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        RepositoryService repositoryService = processEngine.getRepositoryService();
        return repositoryService.createProcessDefinitionQuery().list();
    }

    @Override
    public List<Task> findTasks() {
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        TaskService taskService = processEngine.getTaskService();
        return taskService.createTaskQuery().list();
    }
}
